package com.jlee.android.pimclient.activity;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import com.jlee.android.pimclient.PIMClientConstant;
import com.jlee.android.pimclient.R;

public class PIMClientMainSettingActivity extends ListActivity {
	// Defined for the list items
	private static final String[] LIST_ITEMS = {
		"Calendar Setting",
		"CallLog Setting",
		"Contact Setting",
		"SMS Setting",
		"Save Now"
	};
	private static final int LIST_ITEM_CALENDAR_INDEX = 0;
	private static final int LIST_ITEM_CALLLOG_INDEX = 1;
	private static final int LIST_ITEM_CONTACT_INDEX = 2;
	private static final int LIST_ITEM_SMS_INDEX = 3;
	private static final int LIST_ITEM_SAVE_INDEX = 4;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle(R.string.title_setting);
        
        setListAdapter(new ArrayAdapter<String>(this,
        		android.R.layout.simple_list_item_1, LIST_ITEMS));
        getListView().setTextFilterEnabled(false);
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				switch (position) {
				case LIST_ITEM_CALENDAR_INDEX:
					startActivity(PIMClientCalendarSettingActivity.class);
					break;
				case LIST_ITEM_CALLLOG_INDEX:
					startActivity(PIMClientCallLogSettingActivity.class);
					break;
				case LIST_ITEM_CONTACT_INDEX:
					startActivity(PIMClientContactSettingActivity.class);
					break;
				case LIST_ITEM_SMS_INDEX:
					startActivity(PIMClientSMSSettingActivity.class);
					break;
				case LIST_ITEM_SAVE_INDEX:
					// Since we have saved the information on change, no need to do 
					// anything here.
					Toast.makeText(PIMClientMainSettingActivity.this, 
							R.string.infoSavedToast, Toast.LENGTH_SHORT).show();
					break;
				default:
					Log.e(PIMClientConstant.TAG, "Unknown position: " + position);
				}
			}

        });
    }
    
    void startActivity(Class<?> cls) {
    	startActivity(new Intent(this, cls));
    }
}